package frame.laxcen.response;

import frame.laxcen.BaseFrame;
import frame.laxcen.dataobject.DataObject_0001_00;
import frame.laxcen.response.annotation.FrameFeature;
import frame.laxcen.util.FrameReader;
import frame.laxcen.exception.IllegalFrameFormatException;
import frame.util.ByteUtil;

import java.util.HashMap;
import java.util.Map;

// 返回读写器信息
@FrameFeature(MessageType = 0b0001, Mid = 0x00)
public class Response_0001_00 extends BaseResponse {

    public Response_0001_00(BaseFrame baseFrame) throws IllegalFrameFormatException {

        super(baseFrame);

        getContentMap().putAll(explainToMap());
    }

    @Override
    protected Map<String, String> analyzeResponse(FrameReader reader) throws IllegalFrameFormatException {

        Map<String, String> result = new HashMap<>();

        // 应用处理器软件版本

        byte[] version = ByteUtil.intToBytes(reader.readU32());

        result.put("应用处理器软件版本", String.format("V %d.%d.%d", version[1], version[2], version[3]));

        // 读写器名称

        byte[] name = reader.readU8s();

        result.put("读写器名称", new String(name));

        // 读写器上电时间 (秒)

        long time = Integer.toUnsignedLong(reader.readU32());

        result.put("读写器上电时间", time + "秒");

        return result;
    }

    public DataObject_0001_00 getDataObject() {

        return new DataObject_0001_00(getContentMap());
    }
}
